package com.diors.game.example.server.xmldata;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import com.diors.game.engine.arpg.npc.model.NpcBornModel;
import com.diors.game.engine.arpg.npc.model.NpcModel;

/**
 * NPC出生点Data
 * @author	darren.ouyang <ouyang.darren@gmail.com>
 * @date	2013-10-28
 * @version 1.0
 * @copyright Copyright (c) 2013, darren.ouyang
 */
@XmlRootElement(name = "borns")
@XmlAccessorType(XmlAccessType.FIELD)
public class NpcBornData 
{
	
	@XmlElement(name = "born")
	List<NpcBornModel> list;
	
	private Map<Integer, ArrayList<NpcBornModel>> sceneBorns = new HashMap<Integer, ArrayList<NpcBornModel>>();
	
	/**
	 * 加载xml后监听进入
	 * @param u
	 * @param parent
	 * @create	2013-9-16	darren.ouyang
	 */
	void afterUnmarshal(Unmarshaller u, Object parent)
	{
		sceneBorns.clear();
		for(NpcBornModel born : list)
		{
			if (!sceneBorns.containsKey(born.getSceneBaseID()))
				sceneBorns.put(born.getSceneBaseID(), new ArrayList<NpcBornModel>());
			
			sceneBorns.get(born.getSceneBaseID()).add(born);
			
			NpcModel model = XmlDataManager.NPC_DATA.get(born.getNpcBaseID());
			born.setNpcModel(model);
		}
				
		XmlDataManager.log.info("loading NpcBornData size:" + list.size());
		list = null;
	}
	
	public List<NpcBornModel> getSceneBorns (int sceneIDs)
	{
		return sceneBorns.get(sceneIDs);
	}

}
